/*
 * Copyright 2022-2029 heshuixing(https://gitee.com/heshuixing)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mercury.ec.module.air.controller.admin.search;

import com.mercury.ec.framework.air.core.client.dto.search.detr.AirDetrReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.flight.AirSearchFlightReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.pat.AirPatReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.patex.AirPatexReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.price.AirSearchPriceReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.raw.AirRawReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rtkt.AirRtktReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.tgqrule.AirSearchTgqRuleReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.xsfsi.AirXsfsiReqDTO;
import com.mercury.ec.framework.common.pojo.CommonResult;
import com.mercury.ec.framework.common.util.object.BeanUtils;
import com.mercury.ec.module.air.controller.admin.search.vo.detr.AirDetrReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.detr.AirDetrRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.flight.AirSearchFlightReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.flight.AirSearchFlightRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.pat.AirPatReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.pat.AirPatRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.patex.AirPatexReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.patex.AirPatexRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.price.AirSearchPriceReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.price.AirSearchPriceRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.raw.AirRawReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.raw.AirRawRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.rt.AirRtReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.rt.AirRtRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.rtkt.AirRtktReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.rtkt.AirRtktRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.tgqrule.AirSearchTgqRuleReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.tgqrule.AirSearchTgqRuleRespVO;
import com.mercury.ec.module.air.controller.admin.search.vo.xsfsi.AirXsfsiReqVO;
import com.mercury.ec.module.air.controller.admin.search.vo.xsfsi.AirXsfsiRespVO;
import com.mercury.ec.module.air.service.api.AirApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.mercury.ec.framework.common.pojo.CommonResult.success;

/**
 * 机票查询
 *
 * @author hesx
 */
@Tag(name = "管理后台 - 机票查询")
@RestController
@RequestMapping("/air/search")
@Validated
public class AirSearchController {

    @Resource
    private AirApiService airApiService;

    @GetMapping("/flight")
    @Operation(summary = "航班查询")
    @PreAuthorize("@ss.hasPermission('air:search:query')")
    public CommonResult<AirSearchFlightRespVO> getFlight(@Valid AirSearchFlightReqVO reqVO) {
        return success(BeanUtils.toBean(airApiService.getFlight(BeanUtils.toBean(reqVO, AirSearchFlightReqDTO.class)), AirSearchFlightRespVO.class));
    }

    @GetMapping("/price")
    @Operation(summary = "运价查询")
    @PreAuthorize("@ss.hasPermission('air:search:query')")
    public CommonResult<AirSearchPriceRespVO> getPrice(@Valid AirSearchPriceReqVO reqVO) {
        return success(BeanUtils.toBean(airApiService.getPrice(BeanUtils.toBean(reqVO, AirSearchPriceReqDTO.class)), AirSearchPriceRespVO.class));
    }

    @GetMapping("/tgq-rule-list")
    @Operation(summary = "客规查询")
    @PreAuthorize("@ss.hasPermission('air:search:query')")
    public CommonResult<AirSearchTgqRuleRespVO> getTgqRuleList(@Valid AirSearchTgqRuleReqVO reqVO) {
        return success(BeanUtils.toBean(airApiService.getTgqRuleList(BeanUtils.toBean(reqVO, AirSearchTgqRuleReqDTO.class)), AirSearchTgqRuleRespVO.class));
    }

    @GetMapping("/rt")
    @Operation(summary = "RT", description = "提取编码信息")
    public CommonResult<AirRtRespVO> rt(@Valid AirRtReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.rt(BeanUtils.toBean(reqVO, AirRtReqDTO.class)), AirRtRespVO.class));
    }

    @GetMapping("/pat")
    @Operation(summary = "PAT", description = "获取指定编码运价")
    public CommonResult<List<AirPatRespVO>> pat(@Valid AirPatReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.pat(BeanUtils.toBean(reqVO, AirPatReqDTO.class)), AirPatRespVO.class));
    }

    @GetMapping("/patex")
    @Operation(summary = "PATEX", description = "获取指定航班舱位运价")
    public CommonResult<List<AirPatexRespVO>> patex(@Valid AirPatexReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.patex(BeanUtils.toBean(reqVO, AirPatexReqDTO.class)), AirPatexRespVO.class));
    }

    @GetMapping("/xsfsi")
    @Operation(summary = "XSFSI", description = "获取国际指定航班舱位运价")
    public CommonResult<List<AirXsfsiRespVO>> xsfsi(@Valid AirXsfsiReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.xsfsi(BeanUtils.toBean(reqVO, AirXsfsiReqDTO.class)), AirXsfsiRespVO.class));
    }

    @GetMapping("/detr")
    @Operation(summary = "DETR", description = "票号信息提取")
    public CommonResult<AirDetrRespVO> detr(@Valid AirDetrReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.detr(BeanUtils.toBean(reqVO, AirDetrReqDTO.class)), AirDetrRespVO.class));
    }

    @GetMapping("/raw")
    @Operation(summary = "RAW", description = "原指令接口")
    public CommonResult<AirRawRespVO> raw(@Valid AirRawReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.raw(BeanUtils.toBean(reqVO, AirRawReqDTO.class)), AirRawRespVO.class));
    }

    @GetMapping("/rtkt")
    @Operation(summary = "RTKT", description = "提取RTKT信息")
    public CommonResult<AirRtktRespVO> rtkt(@Valid AirRtktReqVO reqVO) {
        return CommonResult.success(BeanUtils.toBean(airApiService.rtkt(BeanUtils.toBean(reqVO, AirRtktReqDTO.class)), AirRtktRespVO.class));
    }
}
